#ifndef __SERVICE_H__
#define __SERVICE_H__


#include "IService.h"
#include "JsonContentListener.h"
#include "IArduino.h"
#include "MessageRouter.h"
#include "Allocator.h"
#include "WString.h"


/** 
* Such objects have access to
* - hardware abstraction
* - message router to send messages
* and are able to process
* - messages 
* - clock events
*/

class Service : public IService, public JsonContentListener{
protected:
	IArduino& arduino_;
	MessageRouter& router_;
	char* name_;
	ILogger& logger_;
public:
	Service(IArduino& arduino, MessageRouter& router, const String& name, ILogger& logger);
	virtual ~Service();
	bool operator==(const Service& s) const;
	virtual void postMessage(const String& msg);
	virtual void onMessage(const String& msg);
	virtual void tick(long milliseconds);
	virtual bool onItem(const String& name, const String& value);
	virtual void onBegin();
	virtual void onEnd();
	virtual void onParseError();
	virtual const char* getName() const;
	virtual bool isInfrastructure() const;
	static char* allocateString(const String& str);
};

#endif
